Miles Sound System SDK 7.2a

Callbacks under DOS

Discussion

Read this section carefully if you plan to use Miles timer or other callbacks (such as an end-of-sample callback). If you don't intend to use callbacks, then this section won't apply to you.

Under DOS, callbacks are usually made to your application on a background interrupt. The ideal callback function is one that does nothing more than write to one or two flag variables and then immediately return back to Miles. Under DOS, the system is in a vulnerable state inside a callback, so you must be careful what code you execute!

The most important thing to remember is you can't call any functions that call any DOS interrupt. I/O is especially not allowed!

Only 32 KB of stack space is available to DOS callback functions. This amount is sufficient for nearly all "callback-safe" actions. Any function that requires a larger stack may switch to its own with the AIL_switch_stack function.

All code and data accessed by the callback function should be page-locked for use in a VMM environment. All callback functions must also be compiled with stack checking turned off. This usually requires a change to your compiler command line (add "-s" in Watcom C++, for example).

Also remember that all global or static variables that are modified by a callback function must be declared with the volatile modifier. Otherwise, the callback function and the foreground may not be able to communicate after the compiler has performed all of its optimizing tricks.

You should also minimize the total amount of work inside a Miles callback. During a callback, Miles is suspended, so other background tasks won't run - mixing will be interrupted, for example, if you take too long.

Again, though, the best advice for callbacks is to simply post a message or set a flag that can be operated on by your foreground task. This technique works on all platforms and you'll never need to worry about the complications that multithreading can cause.

Next Topic (Sharing the CPU under DOS)

Previous Topic (Memory management under DOS)


Group: Overview for DOS: Miles on DOS with 32-bit DOS Extenders
Related Functions: AIL_switch_stack
Related FAQs: What's the deal with callbacks - are they threads, interrupts, system timers, or what?

For technical support, e-mail Miles3@radgametools.com
© Copyright 1991-2007 RAD Game Tools, Inc. All Rights Reserved.